{% extends 'base.html' %}
{# {% from "_macro.html" import pager %} #}
{% import '_macro.html' as pg %}
{% import '_macro.html' as pg2 %}
{% block title %}
    <title>字典编码列表（分页+宏）</title>
{% endblock title %}

{% block crumb %}
    <a class="maincolor" href="#">系统功能</a>
    <span class="c-666 en">&gt;</span>
    <a class="maincolor" href="/list_dict">字典管理（宏分页）</a>
{% endblock crumb %}

{% block content %}
<article class="cl pd-20">
    <!-- 字典类型 -->
    <div class="row">
        <form class="form col-sm-5 col-md-5 col-lg-5" id="form-dict" >
            <!-- 如果有表单 -->
            {# {{ form.csrf_token }} #}
            <!-- 如果没有表单 -->
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />

            <legend class="">字典类型列表</legend>
            <div class="panel panel-default mt-10">
                <a class="btn btn-primary-outline radius f-r size-MINI mr-20 mt-5 va-m" href="{{ url_for('user.new_user') }}">添加</a>
                <a class="btn btn-primary-outline radius f-r size-MINI mr-20 mt-5 va-b" id="ajax-test" href="#">ajax_test</a>
                {% if dicts %}
                <table class="table table-border table-bg table-bordered table-hover">
                    <thead class="text-c">
                        <tr>
                            <th>序号</th>
                            <th>id</th>
                            <th>字段类型</th>
                            <th>使用状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for dict in dicts %}
                        <tr class="dict-id">
                            <td>{{ loop.index + ((pagination.page - 1) * pagination.per_page) }}</td>
                            <td class="dict" value="{{ dict.id }}">{{ dict.id }}</td>
                            <td>{{ dict.name }}</td>
                            <td>{{ dict.isUse }}</td>
                            <td>
                                <div class="cl">
                                    <a class="btn btn-default size-MINI radius f-l" href="{{ url_for('admin.edit_dict', dict_id=dict.id) }}">编辑</a>
                                    <div class="inline f-l" method="post" action="{{ url_for('admin.delete_dict', dict_id=dict.id, next=request.full_path) }}">
                                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                                        <button type="submit" class="btn btn-danger-outline size-MINI" onclick="return confirm('确认删除？');">删除</button>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                    <tfoot class="text-c">
                        <tr>
                            <th>序号</th>
                            <th>id</th>
                            <th>字段类型</th>
                            <th>使用状态</th>
                            <th>操作</th>
                        </tr>
                    </tfoot>
                </table>
                {% else %}
                <div class="tip"><h5>没有数据</h5></div>
                {% endif %}
                {{ pg.my_paginate(pagination,url_for('admin.list_dict')) }}
            </div>
        </form>
    </div>
    <!-- 字典代码  -->
    <div class="row">
        <form class="form col-sm-5 col-md-5 col-lg-5 " id="form-code" >
            <!-- 如果有表单 -->
            {# {{ form.csrf_token }} #}
            <!-- 如果没有表单 -->
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />

            <legend class="">字典代码列表</legend>
            <div class="panel panel-default mt-10">
                <a class="btn btn-primary-outline radius f-r size-MINI mr-20 mt-5 va-m" href="{{ url_for('user.new_user') }}">添加</a>
                <a class="btn btn-primary-outline radius f-r size-MINI mr-20 mt-5 va-b" id="codetext" href="#}}">{{ textStatus }}</a>
                {% if codes %}
                <table class="table table-border table-bg table-bordered table-hover">
                    <thead class="text-c">
                        <tr>
                            <th>序号</th>
                            <th>父id</th>
                            <th>字段类型</th>
                            <th>使用状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for code in codes %}
                        <tr>
                            <td>{{ loop.index + ((cpagination.page - 1) * cpagination.per_page) }}</td>
                            <td>{{ code.typedict_id }}</td>
                            <td>{{ code.name }}</td>
                            <td>{{ code.isUse }}</td>
                            <td>
                                <div class="cl">
                                    <a class="btn btn-default size-MINI radius f-l" href="#">编辑</a>
                                    <div class="inline f-l" method="post" action="#">
                                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                                        <button type="submit" class="btn btn-danger-outline size-MINI" onclick="return confirm('确认删除？');">删除</button>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                    <tfoot class="text-c">
                        <tr>
                            <th>序号</th>
                            <th>父id</th>
                            <th>字段类型</th>
                            <th>使用状态</th>
                            <th>操作</th>
                        </tr>
                    </tfoot>
                </table>
                {% else %}
                <div class="tip"><h5>{{ vdata }}</h5></div>
                {% endif %}
                {{ pg2.code_paginate(cpagination,url_for('admin.list_code')) }}
            </div>
        </form>
    </div>
</article>
{% endblock content %}

{% block myscript %}
<script type="text/javascript">
    $("table tr").on('click',function(){
        var tr = $(this);
        var td = tr.find("td");
        // alert("本行数据id=" + td[1].innerHTML)
        var fid = td[1].innerHTML
        // alert(" the fid = " + fid);
        $.get('list_code',{
            'typeid': fid
        },function(data, textStatus){
            // $("#codetext").html(textStatus);
            console.log("status = " + textStatus)
            //alert("Data Loaded: " + data);
        });
    });

    $("#ajax-test").click(function(){
        alert("我回来了！");
    })

</script>
{% endblock myscript %}
